<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: content_manager.php 226 2013-09-22 11:31:34Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 226 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 11:31:34 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require_once(DIR_FS_INC.'inc.format_filesize.php');
require_once(DIR_FS_INC.'inc.get_url_friendly_text.php');
if(MODULE_SEO_URL_INDEX_STATUS == 'True') {
	require_once (DIR_FS_INC.'inc.seo_url.php');
	!$seo_url ? $seo_url = new SeoUrl() : false;
}

$languages = get_languages();

if($_GET['special']=='delete') {
	$db->db_query("DELETE FROM ".TABLE_CONTENT_MANAGER." WHERE content_id = ".$db->db_prepare((int)$_GET['coID']));
	if(MODULE_SEO_URL_INDEX_STATUS == 'True')
		$seo_url->deleteFromDB('content_group', $_GET['coID']);
	redirect(href_link(FILENAME_CONTENT_MANAGER));
}

if($_GET['id'] == 'update' || $_GET['id'] == 'insert') {
	$group_ids = '';
	if(isset($_POST['groups']))
		foreach($_POST['groups'] as $b)
			$group_ids .= 'c_'.$b."_group ,";

	$customers_statuses_array = get_customers_statuses();
	if(strstr($group_ids, 'c_all_group')) {
		$group_ids = 'c_all_group,';
		for ($i=0;$n=sizeof($customers_statuses_array),$i<$n;$i++)
			$group_ids .='c_'.$customers_statuses_array[$i]['id'].'_group,';
	}

	if($content_file = try_upload('file_upload', DIR_FS_CATALOG.'media/content/'))
		$content_file_name = $content_file->filename;
	
	for($i = 0, $n = sizeof($languages); $i < $n; $i++) {
		$lid = $languages[$i]['id'];

		$sql_data_array = array('languages_id' => $lid,
								'content_title' => $_POST['cont_title_'.$lid],
								'content_heading' => $_POST['cont_heading_'.$lid],
								'content_text' => stripslashes($_POST['cont_'.$lid]),
								'content_file' => ($_POST['select_file'] != 'default' ? $_POST['select_file'] : ''),
								'content_status' => ($_POST['status'] == 'yes' ? 1 : 0),
								'parent_id' => $_POST['parent'],
								'content_url_alias' => (!empty($_POST['cont_url_alias_'.$lid]) ? get_url_friendly_text($_POST['cont_url_alias_'.$lid]) : ''),
								'group_ids' => $group_ids,
								'content_group' => $_POST['content_group'],
								'sort_order' => $_POST['sort_order'],
								'file_flag' => $_POST['file_flag'],
								'content_out_link' => $_POST['content_out_link'],
								'content_link_target' => $_POST['content_link_target'],
								'content_col_top' => $_POST['content_col_top'],
								'content_col_left' => $_POST['content_col_left'],
								'content_col_right' => $_POST['content_col_right'],
								'content_col_bottom' => $_POST['content_col_bottom'],
								'content_show_pdf' => $_POST['content_show_pdf'],
								'content_show_print' => $_POST['content_show_print'],
								'content_show_back' => $_POST['content_show_back'],
								'content_link_type' => $_POST['content_link_type'],
								'content_meta_title' => $_POST['cont_meta_title_'.$lid],
								'content_meta_description' => $_POST['cont_meta_description_'.$lid],
								'content_meta_keywords' => $_POST['cont_meta_keywords_'.$lid]);
		if($_GET['id'] == 'update') {
			$db->db_perform(TABLE_CONTENT_MANAGER, $sql_data_array, 'update', "content_id = '".(int)$_POST['coID']."' AND languages_id = '".(int)$lid."' ");
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$seo_url->updateSeoDBTable('content', $_POST['content_group']);
	
		} else {
			$db->db_perform(TABLE_CONTENT_MANAGER, $sql_data_array);
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$seo_url->insertSeoDBTable('content', $db->db_insert_id());
		}
	}
	
	if(isset($_POST['apply_content']))
		redirect(href_link('content_manager.php', getMenuID('content_manager').'&action=edit&coID='.(isset($_POST['coID']) ? $_POST['coID'] : $db->db_insert_id())));
	else
		redirect(href_link('content_manager.php'));
}

require('includes/metatag.php'); ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php');?>
<div id="wrapper">
	<table class="outerTable">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES.'column_left.php');?>
			</td>
			<td class="boxCenter" valign="top">
				<table width="100%">
					<tr>
						<td>
							<table class="table_pageHeading" width="100%">
								<tr>
									<td class="pageHeading">
										<?php echo HEADING_TITLE;?>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<?php
								if(!$_GET['action']) {
									if(function_exists(curl_init)) {
										$data = curl_init('http://www.janolaw.de/internetrecht/agb/agb-hosting-service/seo_mecari-header.html');
										curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
										$output = curl_exec($data);
	
										curl_close($data);
	
									} elseif($file = file_get_contents('http://www.janolaw.de/internetrecht/agb/agb-hosting-service/seo_mecari-header.html')) {
										$output = $file;
	
									} else {
										$host = 'janolaw.de';
										$uri  = '/internetrecht/agb/agb-hosting-service/seo_mecari-header.html';
	
										header("Content-type: text/plain");
										$sock = fsockopen($host, 80, $errno, $errstr, 5);
										fputs($sock, "GET ".$uri." HTTP/1.1\r\n");
										fputs($sock, "Host: ".$host."\r\n");
										fputs($sock, "Connection: close\r\n\r\n");
										$result = array();
										while(!feof($sock))
										$result[] = fgets($sock, 4096);
										fclose($sock);
										if(!empty($result['1'])) {
											for($i = 1, $size = sizeof($result); $i < $size; ++$i) {
												if(!empty($result[$i]) || $result[$i] !='0')
												$output .= $result[$i];
											}
										}
									}
									echo '<table class="main" style="margin: 10px; border: 1px solid #ccc;">';
									echo '<tr><td>Werbung</td></tr>';
									echo '<tr><td class="advertising_content_manager">'.utf8_encode($output).'</td></tr>';
									echo '</table><br />';
								}
							?>
							<table width="100%">
								<tr>
									<td>
										<?php if(!$_GET['action']) { ?>
											<div class="main" align="right"><em><?php echo CONTENT_NOTE; ?></em></div>
											<?php
												spaceUsed(DIR_FS_CATALOG.'media/content/');
												echo '<div class="main"><em>'.USED_SPACE.' '.format_filesize($total).'</em></div>';
											
											if(!$_GET['action']) { ?>
												<br /><div style="text-align:right">
													<a class="button" onclick="this.blur();" href="<?php echo href_link(FILENAME_CONTENT_MANAGER,'action=new'); ?>">
														<?php echo BUTTON_NEW_CONTENT; ?>
													</a>
												</div>
												<?php
											}
											function GetContent($lang_id, $parent_id = 0, $level = 1, $spacer = '&lfloor; ') {
												global $db;
												$content_data = $db->db_query("SELECT
																					content_id,
																					categories_id,
																					parent_id,
																					group_ids,
																					languages_id,
																					content_title,
																					content_url_alias,
																					content_heading,
																					content_out_link,
																					content_link_type,
																					content_text,
																					sort_order,
																					file_flag,
																					content_file,
																					content_status,
																					content_group,
																					content_delete
																				FROM
																					".TABLE_CONTENT_MANAGER."
																				WHERE
																					languages_id='".$lang_id."'
																				AND
																					parent_id = '".$parent_id."'
																				ORDER BY
																					content_group, sort_order ");
												
												if($content_data->_numOfRows) {
													while(!$content_data->EOF) {
														$file_flag = $db->db_query("SELECT file_flag_name FROM ".TABLE_CM_FILE_FLAGS." WHERE file_flag=".$content_data->fields['file_flag']);
														if($ii % 2 == 0)
															$f = 'dataTableRow';
														else
															$f = '';
														$c .= '	<tr class="'.$f.'" onmouseover="this.className=\'dataTableRowOver\'" onmouseout="this.className=\''.$f.'\'">';
														$c .= '		<td align="left">';
																		if($content_data->fields['content_group'] == '0') {
														$c .= '				<img align="left" src="images/delete.gif" alt="" /> <span style="color:#b20000;margin-left:5px"><strong>';
														$c .=				($level > 1 ? $spacer : ' ').$content_data->fields['content_title'];
														$c .= '				</strong><br />Sie haben keine Sprachgruppe definiert, daher wurde keine SEO URL erzeugt!</span>';
																		} else
														$c .=				($level > 1 ? $spacer : ' ').$content_data->fields['content_title'];
			
																		if($content_data->fields['content_delete'] == '0')
														$c .= '				<span style="color:#b20000">*</span>';
			
																		if($content_data->fields['content_url_alias'] !='')
														$c .= '			<br /><span style="font-size:85%;color:#666"><em>URL Alias: '.$content_data->fields['content_url_alias'].'</em><span>';
														$c .= '		</td>';
														$c .= '		<td align="center">'.$content_data->fields['content_group'].'</td>';
														$c .= '		<td align="center">'.$content_data->fields['sort_order'].'</td>';
														$c .= '		<td align="center">';
																		if(!empty($content_data->fields['content_file']))
														$c .= 				$content_data->fields['content_file'];
																		else
														$c .= '				- ';
														$c .= '		</td>';
														$c .= '		<td align="center">
																		'.($content_data->fields['content_status'] == 0 ? '<img src="images/icons/cross.png" alt="'.TEXT_NO.'" />' : '<img src="images/icons/tick-circle.png" alt="'.TEXT_YES.'" />').
																	'</td>';
														$c .= '		<td align="center">'.$file_flag->fields['file_flag_name'].'</td>';
														$c .= '		<td align="center">'.(!empty($content_data->fields['content_out_link']) ? '<img src="images/icons/tick-circle.png" alt="'.TEXT_YES.'" />' : '-').'</td>';
														
														
														$c .= '		<td align="right">';
																		if($content_data->fields['content_delete']=='1') {
														$c .= '				<a href="'.href_link(FILENAME_CONTENT_MANAGER, 'special=delete&coID='.$content_data->fields['content_id']).'" onclick="return confirm(\''.CONFIRM_DELETE.'\')">'.
																				image(DIR_WS_ICONS.'delete.gif',TEXT_DELETE,'','','style="cursor:pointer" onclick="return confirm(\''.DELETE_ENTRY.'\')"').'
																			</a>';
																		}
														$c .= '			<a href="'.href_link(FILENAME_CONTENT_MANAGER,'action=edit&coID='.$content_data->fields['content_id']).'">'.
																			image(DIR_WS_ICONS.'document--pencil.png',TEXT_EDIT,'','','style="cursor:pointer"').'
																		</a>';
																		if(!empty($content_data->fields['content_out_link'])) {
														$c .= '				<a style="cursor:pointer" target="_blank" href="'.$content_data->fields['content_out_link'].'">'.
																				image(DIR_WS_ICONS.'preview.gif',TEXT_PREVIEW,'','','style="cursor:pointer"').'
																			</a>';
																		} else {
														$c .= '				<a style="cursor:pointer" onclick="javascript:window.open(\''.href_link(FILENAME_CONTENT_PREVIEW,'coID='.$content_data->fields['content_id']).'\', \'popup\', \'toolbar=0, width=640, height=600\')">'.
																				image(DIR_WS_ICONS.'preview.gif',TEXT_PREVIEW,'','','style="cursor:pointer"').'
																			</a>';
																		}
														$c .= '		</td>';
														
														$c .= '	</tr>';
														$c .= GetContent($lang_id, $content_data->fields['content_group'], $level+1, '&nbsp;&nbsp;&nbsp;'.$spacer);
														$content_data->MoveNext();
													}
												}
												if($c)
													return $c;
											}
											
											// Display Content
											?>
												<table width="100%" class="dataTable">
													<tr class="dataTableHeadingRow">
														<td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_CONTENT_TITLE; ?></td>
														<td class="dataTableHeadingContent" align="middle"><?php echo TABLE_HEADING_CONTENT_GROUP; ?></td>
														<td class="dataTableHeadingContent" align="middle"><?php echo TABLE_HEADING_CONTENT_SORT; ?></td>
														<td class="dataTableHeadingContent" width="2%"align="left"><?php echo TABLE_HEADING_CONTENT_FILE; ?></td>
														<td class="dataTableHeadingContent" nowrap="nowrap" align="left"><?php echo TABLE_HEADING_CONTENT_STATUS; ?></td>
														<td class="dataTableHeadingContent" nowrap="nowrap" align="middle"><?php echo TABLE_HEADING_CONTENT_BOX; ?></td>
														<td class="dataTableHeadingContent" nowrap="nowrap" align="middle">Link ?</td>
														<td class="dataTableHeadingContent last" align="middle"><?php echo TABLE_HEADING_CONTENT_ACTION; ?>&nbsp;</td>
													</tr>
												<?php echo GetContent((int)$_SESSION['languages_id']); ?>
												</table>
											<?php
										} else
											include(DIR_WS_MODULES.'content_manager.php');

										if(!$_GET['action']) { ?>
											<br /><div style="text-align:right">
												<a class="button" onclick="this.blur();" href="<?php echo href_link(FILENAME_CONTENT_MANAGER,'action=new'); ?>">
													<?php echo BUTTON_NEW_CONTENT; ?>
												</a>
											</div>
											<?php
										} ?>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php');